"use strict";

module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.createTable("products", {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER,
      },
      name: {
        type: Sequelize.STRING(100),
        allowNull: false,
        comment: "商品名称",
      },
      category_id: {
        type: Sequelize.INTEGER,
        allowNull: false,
        comment: "分类ID",
      },
      brand_id: {
        type: Sequelize.INTEGER,
        comment: "品牌ID",
      },
      price: {
        type: Sequelize.DECIMAL(10, 2),
        allowNull: false,
        comment: "价格",
      },
      original_price: {
        type: Sequelize.DECIMAL(10, 2),
        comment: "原价",
      },
      cost_price: {
        type: Sequelize.DECIMAL(10, 2),
        comment: "成本价",
      },
      stock: {
        type: Sequelize.INTEGER,
        allowNull: false,
        defaultValue: 0,
        comment: "库存",
      },
      sales: {
        type: Sequelize.INTEGER,
        allowNull: false,
        defaultValue: 0,
        comment: "销量",
      },
      cover_image: {
        type: Sequelize.STRING(255),
        comment: "封面图",
      },
      description: {
        type: Sequelize.TEXT,
        comment: "商品描述",
      },
      detail: {
        type: Sequelize.TEXT,
        comment: "商品详情",
      },
      status: {
        type: Sequelize.BOOLEAN,
        allowNull: false,
        defaultValue: true,
        comment: "状态(1:上架,0:下架)",
      },
      is_hot: {
        type: Sequelize.BOOLEAN,
        allowNull: false,
        defaultValue: false,
        comment: "是否热销",
      },
      is_new: {
        type: Sequelize.BOOLEAN,
        allowNull: false,
        defaultValue: false,
        comment: "是否新品",
      },
      is_recommend: {
        type: Sequelize.BOOLEAN,
        allowNull: false,
        defaultValue: false,
        comment: "是否推荐",
      },
      sort_order: {
        type: Sequelize.INTEGER,
        allowNull: false,
        defaultValue: 0,
        comment: "排序",
      },
      keywords: {
        type: Sequelize.STRING(255),
        comment: "关键词",
      },
      unit: {
        type: Sequelize.STRING(20),
        comment: "单位",
      },
      weight: {
        type: Sequelize.DECIMAL(10, 2),
        comment: "重量(kg)",
      },
      volume: {
        type: Sequelize.DECIMAL(10, 2),
        comment: "体积(m³)",
      },
      created_at: {
        allowNull: false,
        type: Sequelize.DATE,
      },
      updated_at: {
        allowNull: false,
        type: Sequelize.DATE,
      },
    });
  },
  down: (queryInterface, Sequelize) => {
    return queryInterface.dropTable("products");
  },
};
